Skip to main content

Sound Alternator

In this project, we create a police siren by using LEDs which blink constantly and a speaker which produces specific frequency sounds.

Circuit

Police Siren

Components

  • 1 Smowboard Think Mini
  • 1 Speaker
  • 1 BC547 transistor
  • 1 100k ohm resistor
  • 2 100 ohm resistors
  • 1 10uF capacitor
  • 2 red LEDs
  • 5 male-to-female jumper wires
  • 1 male-to-male jumper wires

In this circuit, we connect a transistor on the breadboard. We connect the 100k ohm resistor across the base-collector junction of the transistor. We connect the negative terminal of the capacitor to the base of the transistor and the positive terminal of the capacitor to the pin number 21 of Smowboard. We connect one terminal of the speaker to Vin pin of the Smowboard while its other terminal is connected to the collector of transistor. The emiiter of the transisitor is grounded by connecting it to the ground of Smowboard. We connnect both the LEDs on the breadboard. The LEDs are grounded by connecting their cathode to the ground of Smowboard. A 100 ohm resistor is connected in series to the cathode side of each LED to limit the current. The anode of one LED is connected to the pin number 2 of Smowboard while the anode of other LED is connected to the pin number 4 of Smowboard. Both the LEDs are controlled by the Smowboard.

The speaker is connected to the Smowboard using capacitor and transistor. The Smowboard controls the frequency of the sound. Thus the speaker produces the sound of a siren by producing sound of frequencies used in police sirens. Also the Smowboard controls the voltage across the LEDs. A current flows across the LEDs due to this voltage and the LEDs glow alternatively giving the effect of an actual police siren.

Flow

Police Siren


[{"id":"f845b2ee.cde6e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"36877fc3.a4797","type":"common/on interval","z":"f845b2ee.cde6e","config_props":{"name":"","interval":"0.2"},"outputProps":{},"dependency_set":{},"x":200,"y":160,"wires":[["306a9a53.5534a6"]]},{"id":"306a9a53.5534a6","type":"smow_pin/write","z":"f845b2ee.cde6e","config_props":{"name":"","pin_number":"2","level":"1"},"outputProps":{},"dependency_set":{},"x":370,"y":160,"wires":[["6dd9c0d6.fa72b"]]},{"id":"6dd9c0d6.fa72b","type":"smow_pin/write","z":"f845b2ee.cde6e","config_props":{"name":"","pin_number":"4","level":"0"},"outputProps":{},"dependency_set":{},"x":550,"y":160,"wires":[["dbc9279a.2de7c8"]]},{"id":"dbc9279a.2de7c8","type":"common/delay","z":"f845b2ee.cde6e","config_props":{"name":"","period":"0.1"},"outputProps":{},"dependency_set":{},"x":750,"y":160,"wires":[["c55d1ccb.3b616"]]},{"id":"c55d1ccb.3b616","type":"smow_pin/write","z":"f845b2ee.cde6e","config_props":{"name":"","pin_number":"2","level":"0"},"outputProps":{},"dependency_set":{},"x":370,"y":240,"wires":[["110d5a20.21cf06"]]},{"id":"110d5a20.21cf06","type":"smow_pin/write","z":"f845b2ee.cde6e","config_props":{"name":"","pin_number":"4","level":"1"},"outputProps":{},"dependency_set":{},"x":550,"y":240,"wires":[["7cb6026f.2983cc"]]},{"id":"7cb6026f.2983cc","type":"common/delay","z":"f845b2ee.cde6e","config_props":{"name":"","period":"0.1"},"outputProps":{},"dependency_set":{},"x":750,"y":240,"wires":[[]]},{"id":"17d42b0b.7282d5","type":"common/on interval","z":"f845b2ee.cde6e","config_props":{"name":"","interval":"0.8"},"outputProps":{},"dependency_set":{},"x":200,"y":360,"wires":[["dd319649.a7e2b8"]]},{"id":"dd319649.a7e2b8","type":"smow_pulse/sound","z":"f845b2ee.cde6e","config_props":{"name":"","config":"89fbe5b7.ab6648","on_off":"1","frequency":"850"},"outputProps":{},"dependency_set":{"switch_on":true},"x":420,"y":360,"wires":[["39677368.51493c"]]},{"id":"264424b0.013dac","type":"smow_pulse/sound","z":"f845b2ee.cde6e","config_props":{"name":"","config":"89fbe5b7.ab6648","on_off":"1","frequency":"950"},"outputProps":{},"dependency_set":{"switch_on":true},"x":420,"y":440,"wires":[["b2cf3b5c.25f6d8"]]},{"id":"39677368.51493c","type":"common/delay","z":"f845b2ee.cde6e","config_props":{"name":"","period":"0.4"},"outputProps":{},"dependency_set":{},"x":690,"y":360,"wires":[["264424b0.013dac"]]},{"id":"b2cf3b5c.25f6d8","type":"common/delay","z":"f845b2ee.cde6e","config_props":{"name":"","period":"0.4"},"outputProps":{},"dependency_set":{},"x":690,"y":440,"wires":[[]]},{"id":"89fbe5b7.ab6648","type":"smow_pulse/analog write config","z":"","config_props":{"name":"","pin":"21","duty_resolution":"11","timer_num":"0","led_channel":"0","clk_config":"0","speed_mode":"0"},"outputProps":{},"dependency_set":{}}]

To import this code to the Studio, copy it and paste it into the import nodes dialog box in the import section.

Lets understand the code,

  • We create two flows, one for blinking the LEDs and the other for producing sound from the siren.
  • The flow for blinking the LEDs starts with an on interval node. All next nodes connected to it get triggered repeatedly after the specified interval of time.
  • Double click on the node to change its properties.
  • We set the time interval of the on-interval node to 0.2 seconds.
  • We connect two pin write nodes. The 'pin number' is set to 2 and 'pin level' is set to 0 for the first pin write node. For the second pin write node, the 'pin number' is set to 4 and 'pin level' is set as 0.
  • This will glow the LED connected at the pin number 2 of Smowboard and the keep the LED connected to pin number 4 OFF.
  • Now, we use a delay node to add a delay of 0.1 seconds before the next two pin write nodes run.
  • The first LED will glow while the second LED will remain OFF during this 0.1 seconds.
  • After the delay node, we connect two more pin write nodes. For the first node we set the 'pin number' as 2 and 'pin level' as 0. For the second node, the 'pin number' is set to 4 while 'pin level' is set to 1.
  • This will keep the LED connected to pin number 2 of Smowboard, OFF and glow the LED connected to pin number 4.
  • We again add a delay of 0.1 seconds using the delay node. The flow doesn't restart before this nodes's activity (i.e delay) finishes.
  • The flow for the siren also begins with an on interval node who's time interval is set as 0.8 seconds.
  • We use a sound node to get the sound from the siren. Configure the node by clicking on the pencil icon on the 'output' property of the node. Set the 'output pin' to 21 as we have connected the speaker to the pin number 21 of Smowboard.
  • We then click on Add and Done to complete the configuration.
  • We set the 'Switch' property to 'Turn ON' and 'Tone' to 850Hz. This node will produce sound of frequency 850Hz.
  • We now add a delay of 0.4 seconds using a delay node. The next node, sound does not run before this node's activity (i.e delay) finishes.
  • The speaker will keep producing sound of 850Hz frequency for this 0.4 seconds.
  • We connect another sound node and set its 'Tone' to 950Hz. This node will produce sound of frequency 950Hz.
  • We again use a delay node to add a delay of 0.4 seconds. The flow doesn't restart before thhis node's activity (i.e delay) finishes.
  • The speaker will keep producing sound of frequency 950Hz for this 0.4 seconds.
  • Now, we upload the code to the Smowboard using the upload button on the Studio.
  • We can see that the LEDs keep blinking alternatively after every 0.1 seconds while the speaker produces sounds of 850Hz and 950Hz frequency alternatively every 0.4 seconds creaing the effect of a police siren.

Output

Police Siren


Learn Coding and Electronics easily using Smowcode.